package com.whf.config;

import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.api.WxOpenService;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2018/7/18 0018.
 */
@Component
public class WeChatOpenConfig {
    @Autowired
    private WeChatConfig weChatConfig;
    @Bean
    public WxOpenService wxOpenService(){
        //配置文件
        WxOpenService wxOpenService=new WxOpenServiceImpl();
        //配置文件从wxMpConfigStorage()中获取
        wxOpenService.setWxOpenConfigStorage(wxOpenConfigStorage());
        return wxOpenService;
    }
    @Bean
    public WxOpenConfigStorage wxOpenConfigStorage(){
        WxOpenInMemoryConfigStorage wxOpenConfigStorage=new WxOpenInMemoryConfigStorage();
        //获取配置文件中的参数
        wxOpenConfigStorage.setComponentAppId(weChatConfig.getOpenAppId());
        wxOpenConfigStorage.setComponentAppSecret(weChatConfig.getOpenAppSecret());
        return wxOpenConfigStorage;
    }

}
